<?php
/*
 * This page is for upgrade to SalusBaby from SalusMe.
 */
include '../config.php';
if (!isset($_COOKIE['vid'])) {
    header('Location:http://' . $_SERVER['HTTP_HOST'] . '/salusme');
} else {
    session_start();
}
?>

<?php include '../head.php'; ?>
<title>Upgrade to SalusBaby</title>
<head>
    <style>
        .bb th, .bb td{
            border-bottom:  1px #000000 dotted !important ;
        }
    </style>
    <script type="text/javascript">
        $(document).ready(function(){

            
                      
            $('#prapid_code_no').click(function(){
                $('#prepaid_code').hide();
            });
            $('#prapid_code_yes').click(function(){
                $('#prepaid_code').show();
            });
                        

        });
    </script>
</head>
<body>
    <div id="wrapper">

        <?php include '../header_profile.php'; ?>        

        <div id="mainContent" style="border: 1px #000000 dotted ; width: 600px; margin-left: 30%; "><br/>
            <center><h1>Upgrade to <br/><img src="http://<?= $_SERVER['HTTP_HOST'] ?>/salusme/include/images/baby.png" /> </h1></center><hr>
            <?php
            if (!isset($_POST['submit'])) {
                ?>


                <form method="post"  action="upgrade_to_baby.php" >
                    <div>
                        <div class="float_left">
                            <div class="float_left padding_5"><div><input class="cursor" checked type="radio" id="prapid_code_yes" value="yes" name="prapid"/></div><div class="title_home">Yes</div></div>
                            <div class="float_left padding_5"><div><input class="cursor" type="radio" id="prapid_code_no" name="prapid" value="no"/></div><div  class="title_home">No</div></div>
                            <div class="clear"></div>
                        </div>
                        <div><input type="text" id="prepaid_code" name="prepaid_code" placeholder="Preee-paid code" class="text_field_prepaid"/></div>
                        <input type="submit" name="submit" value="NEXT" />
                        <div class="clear"></div>
                    </div>
                </form>
                <?php
            } else {

                if ($_POST['prapid'] == 'yes') {
                    if (trim($_POST['prepaid_code']) == '') {
                        echo '<font color = red>Please, Enter a code.</font><br>';
                        die;
                    } else {
                        // check if code then ok else skip to next
                        $prepaid_code = $_POST['prepaid_code'];
                        $p1 = mysql_query("select * from salus_prepaid_codes where prepaid_code = '" . $prepaid_code . "' ") or die(mysql_error());
                        if (mysql_num_rows($p1) == 0) {
                            echo '<font color = red>Invalid Code.</font>';
                            die;
                        } else {
                            while ($row = mysql_fetch_array($p1)) {
                                $idp = $row[0];     //prepaid code id            
                                $seller_id = $row[1]; //seller detail id
                                $us = $row[3];  // user id            
                            }
                            $p2 = mysql_query("select * from salus_seller_details where sr = $seller_id ") or die(mysql_error());
                            while ($row1 = mysql_fetch_array($p2)) {
                                $pro_id = $row1['product_id'];
                                $pro_detail_id = $row1['pro_detail_id'];
                                $discount = $row1['discount'];
                            }
                            if ($pro_id != 2) {
                                $err = '<font color = red>Code is not for this product.</font>';
                                echo $err;
                                die();
                            }

                            if ($us != '') {
                                $err = '<font color = red>Code is already used.</font>';
                                echo $err;
                                die();
                            } else {
                                
                            }
                        }
                        ?>

                        <!--                       -->
                        <div style="font-size: 16px; font-weight: bold; text-align: center; border: 1px red dotted; width: 400px; margin-left: 20%;" >
                            <h3><font color="green">Attention !!!</font></h3>
                            <?php
                            $_SESSION['started'] = time();
                            $_SESSION['ending'] = $_SESSION['started'] + (10 * 60);  # sesion expire in 10 minutes
                            $_SESSION['pre_code'] = $prepaid_code;
                            $_SESSION['code_id'] = $idp;
                            $_SESSION['type'] = 'seller';
                            $_SESSION['proid'] = $pro_detail_id;
                            $_SESSION['discount'] = $discount;
                            ?>
                            Pre-paid code is verified.<br>
                            You are registering with Pre-paid code.<br>
                            <a href="next.php?v=code&pdid=<?= $pro_detail_id ?>">Click to go next step.</a>
                        </div>

                        <?php
                    }
                } else {
                    ?>
                    <div style="font-size: 16px; font-weight: bold; text-align: center; border: 1px red dotted; width: 400px; margin-left: 20%;" >
                        <h3><font color="green">Attention !!!</font></h3>
                        You are registering without Pre-paid code.<br>
                        <a href="next.php?v=direct">Click to go next step.</a>
                    </div>
                    <?php
                }
            }
            ?>
        </div><!-- wrapper over    -->


        <?php
        
        ?>
</body>
</html>